home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c1.zip / DUMP.C < prev    next >
Text File  |  1987-06-18  |  2KB  |  91 lines

  1.  
  2. /*              dump.c          core style dump of a file       */
  3.  
  4. /*              usage: A>DUMP B:BLIP.O                                  */
  5.  
  6.  
  7. char buffer[4096];
  8.  
  9. main(argc,argv)
  10.         int  argc;
  11.         char *argv[]; {
  12.         unsigned i,numin,tot,file;
  13.         char *cfrom;
  14.  
  15.         if (argc < 2) {
  16.                 puts("Missing Filename\n");
  17.                 }
  18.  
  19.         tot=0;
  20.         if ((file=open(argv[1],0)) == -1) {
  21.                 puts("Cannot Open ");
  22.                 puts(argv[1]);
  23.                 exit(1);
  24.                 }
  25.  
  26. /*      read and dump 4k at a time      */
  27.  
  28.         do {
  29.                 numin=read(file,buffer,4096);
  30.                 if (numin == -1) {
  31.                         puts("Cannot Read ");
  32.                         puts(argv[1]);
  33.                         exit(1);
  34.                         }
  35.                 cfrom=0;
  36.                 while (cfrom < numin) {
  37.  
  38. /*      print the offset in hex */
  39.  
  40.                         ohw(cfrom+tot);
  41.                         putchar(' ');
  42.  
  43. /*      print 16 bytes in hex   */
  44.  
  45.                         for (i=0; i < 16; i++) {
  46.                                 putchar(' ');
  47.                                 ohb(buffer[cfrom++]);
  48.                                 }
  49.                         cfrom-=16;
  50.                         puts("  *");
  51.  
  52. /*      print the bytes in ascii        */
  53.  
  54.                         for (i=0; i < 16; i++) {
  55.                                 putchar((buffer[cfrom] >= ' ' && buffer[cfrom] < 0x7f)
  56.                                          ? buffer[cfrom]: '.');
  57.                                 cfrom++;
  58.                                 }
  59.                         puts("*\n");
  60.                         }
  61.                 tot+=numin;
  62.                 }
  63.         while (numin == 4096);
  64.         }
  65.  
  66. /*      print a word in hex     */
  67.  
  68. ohw(wrd)
  69.         unsigned wrd; {
  70.         ohb(wrd>>8);
  71.         ohb(wrd);
  72.         }
  73.  
  74. /*      print a byte in hex     */
  75.  
  76. ohb(byt)
  77.         char byt; {
  78.         onib(byt>>4);
  79.         onib(byt);
  80.         }
  81.  
  82. /*      print a nibble as a hex character       */
  83.  
  84. onib(nib)
  85.         char nib; {
  86.  
  87.         nib&=15;
  88.         putchar((nib >= 10) ? nib-10+'A': nib+'0');
  89.         }
  90.  
  91.